<!DOCTYPE html>
<html>

<head>
	<meta charset='UTF-8'>
	
	<title>Responsive Table</title>
	
	<meta name="viewport" content="width=device-width, initial-scale=1.0">

	<link rel="stylesheet" href="style.css">
	
	<!--[if !IE]><!-->
	<style>
	
	/* 
	Max width before this PARTICULAR table gets nasty
	This query will take effect for any screen smaller than 760px
	and also iPads specifically.
	*/
	@media 
	only screen and (max-width: 760px),
	(min-device-width: 768px) and (max-device-width: 1024px)  {
	
		/* Force table to not be like tables anymore */
		table, thead, tbody, th, td, tr { 
			display: block; 
		}
		
		/* Hide table headers (but not display: none;, for accessibility) */
		thead tr { 
			position: absolute;
			top: -9999px;
			left: -9999px;
		}
		
		tr { border: 1px solid #ccc; }
		
		td { 
			/* Behave  like a "row" */
			border: none;
			border-bottom: 1px solid #eee; 
			position: relative;
			padding-left: 50%; 
		}
		
		td:before { 
			/* Now like a table header */
			position: absolute;
			/* Top/left values mimic padding */
			top: 6px;
			left: 6px;
			width: 45%; 
			padding-right: 10px; 
			white-space: nowrap;
		}
		
		/*
		Label the data
		*/
		td:nth-of-type(1):before { content: "First Name"; }
		td:nth-of-type(2):before { content: "Last Name"; }
		td:nth-of-type(3):before { content: "Job Title"; }
		td:nth-of-type(4):before { content: "Favorite Color"; }
		td:nth-of-type(5):before { content: "Wars of Trek?"; }
		td:nth-of-type(6):before { content: "Porn Name"; }
		td:nth-of-type(7):before { content: "Date of Birth"; }
		td:nth-of-type(8):before { content: "Dream Vacation City"; }
		td:nth-of-type(9):before { content: "GPA"; }
		td:nth-of-type(10):before { content: "Arbitrary Data"; }
	}
	
	/* Smartphones (portrait and landscape) ----------- */
	@media only screen
	and (min-device-width : 320px)
	and (max-device-width : 480px) {
		body { 
			padding: 0; 
			margin: 0; 
			width: 320px; }
		}
	
	/* iPads (portrait and landscape) ----------- */
	@media only screen and (min-device-width: 768px) and (max-device-width: 1024px) {
		body { 
			width: 495px; 
		}
	}
	
	</style>
	<!--<![endif]-->

</head>

<body>

	<div id="page-wrap">

	<h1>Return Results after Import Data in Excel - By Dong Hong</h1>
	
	<?php set_time_limit(0);

$name = "ProductDetail_Output2012_5_25__12_44_56.csv";

$row  = 1;

$fc = iconv('windows-1250', 'utf-8', file_get_contents($name)); 

$c  = str_replace("\t", " ", file_get_contents($name));

$c = str_replace("[:|:]", "\t", $c);
//"\t"

file_put_contents('import.tmp',$c); 
            
$handle = fopen('import.tmp', "r"); 
		
    $rows = array(); 
			
	$tbl = '<table><thead>';
										
   while (($data = fgetcsv($handle, 0, "\t")) !== FALSE) { 
 				
				$num = count($data);        						                				
				
				if ($row == 1)
					{
						$tbl.='<tr>';
					
					   for ($c=0; $c < $num; $c++) 
					 	 {							
            				$tbl.='<th>'.$data[$c].'</th>';
						 }
						 
						 $tbl.= '</tr></thead><tbody>';	
					}		
				else
				    {
						$tbl.='<tr>';
					   
					   //14 = ALSO BOUGHT
					   //18 = REVIEW RATING
					   //19 = REVIEW TITLE
					   //20 = REVIEW DATE
					   //22 = S. IMAGES
					   //23 = M. IMAGES
					   //24 = L. IMAGES
					   
					   $also_bought  = explode("||", $data[14]);
					   $review_rate  = explode("||", $data[18]);
					   $review_title = explode("||", $data[19]);
					   $review_date  = explode("||", $data[20]);
					   
					   $review_c= explode("||", $data[21]);
					   $s_image = explode("||", $data[22]);
					   $m_image = explode("||", $data[23]);
					   $l_image = explode("||", $data[24]);

					   for ($c=0; $c < $num; $c++) 
					 	 {								  						     							
						     if ($c>17 & $c<25) //REVIEW RATING
							    {
								  $s[$c] = explode("||", $data[$c]);
								  								 								  
								  $tbl.='<td>'.show_arr($s[$c]).'</td>';
								  
								  //var_dump($s[$c]);
								  
								  for ($k=0;$k<count($s[$c]);$k++)
								  	  {
										 echo "&nbsp;&nbsp;".$k." = ".$s[$c][$k].' ';  
									  }
						           
								  echo "<br>-----------------------<br>"; 							
								}
							 else	
							 {
							 if ($c==14) { $tbl.='<td>'.show_arr($also_bought).'</td>'; }
							 else				 
							 if ($c>7 && $c<11)
							 	{ $tbl.='<td>'.substr($data[$c],0,130).'...</td>';}
							 else 
            					$tbl.='<td>'.$data[$c].'</td>';
								
								echo $c.".".$data[$c];						  
								
							 }
							 echo "<br>-----------------------<br>"; 
						 }
						 
						 $tbl.= '</tr>';	
					}		
					  echo "<br>================================================<br>";
				$row++;		
      }     
	
	$tbl.= '</tbody></table>';
	  
fclose($handle); 

unlink('import.tmp'); 	

echo $tbl;

function show_arr($a=array())
{
	$s='';
	
	for ($i=0;$i<count($a);$i++)
	 	{
			$s.=$a[$i]."<br>";
		}
  return $s;		
}
?>

	</div>
</body>

</html>
